<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">  
    <head>  
        <title>修改报建资料</title>  
        <script src="/scripts/boot.js"></script>
    </head>  
    <body class="bg-white"> 
    	<div class="title-info"><span>编制计划</span>
	    	<div class="position-rel">
				<div class="position-abs">
					<a onclick="importExcel()" class="newly" iconCls="icon-upload">导入 </a>
	    			<a class="delAll" onclick="delAll()">删除</a>
	    			<div class="boxtemplet">
						<div class="templet"><a>模板下载</a></div>
					    <a class="downExcel"  onclick="downExcel()"></a>
					</div>
				</div>
	    	</div>
    	</div>
    	<div id="datagrid1" multiSelect="true" class="mini-datagrid" style="width:100%; height:627px; margin-top:35px;"  url="/perMonPlan/list" sizeList="[5,10,20,50]" pageSize="20"  idField="user_id">
		    <div property="columns">
		        <div type="checkcolumn" headerAlign="center" align="center"></div>
		        <div type="indexcolumn" headerAlign="center" align="center">序号</div>          
		        <div field="planNature" width="100" headerAlign="center" allowSort="true">计划性质</div>    
		        <div field="taskName" width="100" headerAlign="center" allowSort="true">任务名称名称</div>    
		        <div field="workProduct" width="100" headerAlign="center" allowSort="true">工作成果</div>    
		        <div field="precondition" width="100" headerAlign="center" allowSort="true">前置条件</div>    
		        <div field="startDate" width="100" headerAlign="center" allowSort="true" renderer="ondayRenderer">计划开始时间</div>    
		        <div field="overDate" width="100" headerAlign="center" allowSort="true" renderer="ondayRenderer">计划结束时间</div> 
		        <div field="workTime" width="100" headerAlign="center" allowSort="true">工期</div>    
		        <div field="factPlanStartDate" width="100" headerAlign="center" allowSort="true" renderer="ondayRenderer">实际计划开始时间</div>    
		        <div field="factPlanOverDate" width="100" headerAlign="center" allowSort="true" renderer="ondayRenderer">实际计划结束时间</div>    
		        <div field="factWorkTime" width="100" headerAlign="center" allowSort="true">实际工期</div>    
		        <div field="responsibilityDept" width="100" headerAlign="center" allowSort="true">主责部门</div>    
		        <div field="coordinateDept" width="100" headerAlign="center" allowSort="true">配合部门</div>    
		        <div field="remarks" width="100" headerAlign="center" allowSort="true">备注</div>    
		    </div>
		</div>   
	    	
	    	<!-- <div class="mini-fit"></div>                
		    <div class="mini-toolbar" style="text-align:center;" borderStyle="border-left:0;border-right:0;border-bottom:0;">
		        <a class="mini-button" iconCls="icon-cancel" onclick="CloseWindow('close')">关闭</a>
		    </div> -->
		<script type="text/javascript">
		   	mini.parse();
			var form = new mini.Form("#editForm");
			var i ;
			
			 function SetData(data) {
               console.info(data);
               data = mini.clone(data);
               i = data.id;
                //跨页面传递的数据对象，克隆后才可以安全使用
                $.ajax({
                    url: "/establish/follow/plan/info?id=" + data.id,
                    cache: false,
                    success: function (text) { console.info(text)
                    
                    	var span = $("#attachment");
                 	var listFile = text.listFile;
                 	if(listFile){
                 		
                 	for(var i=0;i<listFile.length;i++ ){
                 		var file = listFile[i];
	                    var name =	file.file_name;
	                    var url =	file.file_url;
	                    var fileid =	file.id;
	                    var a= "<div id='"+fileid+"' class='file-box'>"+
	                    "<a class='file-name' onclick=\"downFile('" +url+"','"+name+"')\">"+name+"</a>"+
	                    "</div>"
	                    span.append(a);
                 	}
                	mini.parse();
                 	}
                    	
                    	var o = mini.decode(text);
                        form.setData(o);
                        form.setChanged(false);
                        
                        
                        mini.get('provinceCombo').setValue(o.item.tSysNation.parentId);
                        provinceChanged();
                        mini.get('cityCombo').setValue(o.item.tSysNation.id);
                        cityChanged();
                         mini.get('itemCombo').setValue(o.item.id);
                    }
                });
              
			    
			    var datagrid = mini.get("datagrid1");
				var dd={"followPlanId":i}
				datagrid.load(dd);
		    }
			//格式化日期
			
			function ondayRenderer(e) {
				if (e.value) {
					var value = new Date(e.value);
					if (value) {
						return mini.formatDate(value, 'yyyy-MM-dd')
					}
				}else{
					return "";
				}
			}
			 //保存
			function save(){
				var flag = checkDate();
				if(!flag){
					return false;
				}
				form.validate();
	            if (form.isValid() == false) return;
	            var data = form.getData();      //获取表单多个控件的数据
	            $.ajax({
					type : "post",
					url : "/establish/follow/plan/edit?id=" + i,
					data : data,
					success : function(msg) {
						CloseWindow("ok")
					}
				});
			}
			//批量删除
			function delAll(){
				 var grid = mini.get("datagrid1");
				var rows = grid.getSelecteds();
				if (rows.length > 0) {
	                if (confirm("确定删除选中记录？")) {
	                    var ids = [];
	                    for (var i = 0, l = rows.length; i < l; i++) {
	                        var r = rows[i];
	                        ids.push(r.id);
	                    }
	                    var id = ids.join(',');
	                    $.ajax({
	                        url: "/establish/follow/delAll?id="+id,
	                        success: function (text) {
	                            grid.reload();
	                        },
	                        error: function () {
	                        }
	                    });
	                }
	            } else {
	                alert("请选中一条记录");
	            }
			}
		

			  //改变省
				function provinceChanged() {
				    var provinceCombo = mini.get("provinceCombo");
				    var cityCombo = mini.get("cityCombo");
				    var id = provinceCombo.getValue();
				    
				    var url = "/city/listByItem?pid=" + id;
				    cityCombo.setUrl(url);
				    
				    
				    var itemCombo = mini.get("itemCombo");
				    var itemurl = "/item/getListBypcrId?"+"city_id=" + id;
				    itemCombo.setUrl(itemurl);
				}
				//改变市
				function cityChanged() {
				    var provinceCombo = mini.get("provinceCombo");
				    var cityCombo = mini.get("cityCombo");
				    var id = cityCombo.getValue();
				    var itemCombo = mini.get("itemCombo");
				    var itemurl = "/item/getListBypcrId?"+"city_id=" + id;
				    itemCombo.setUrl(itemurl);
				}
				
				 
			 //检查开始时间是否小于竣工时间
			 
			 function checkDate(){
				 var start = mini.get("startDate");
				 var over  =  mini.get("overDate");
				 var sd = start.value;
				var od =  over.value;
				 console.log(sd);
				 console.log(od);
				 if(sd>=od){
					 alert("竣工日期必须大于开始日期!")
					 return false;
				 }else{
					 return true;
				 }
			 }
			 
			 //关闭窗口
		    function CloseWindow(action) {
		        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
		        else window.close();
		    }
			 
		    function setFile_url(url,num){
		    	var old_url=mini.get('file_url').getValue();
		    	if(old_url!=""){
		    		old_url=old_url+";"
		    	}
		    	mini.get('file_url').setValue(old_url+url);
		    }
		    function setFile_name(name,num){

		    	var old_name=mini.get('file_name').getValue();
		    	if(old_name!=""){
		    		old_name=old_name+";"
		    	}
		    	mini.get('file_name').setValue(old_name+name);
		    	
		    	var span = $("#span");
		    	span.append(name+"  ;");
		    }
		    
		    function importExcel(){
				 mini.open({
			            title: "上传面板",
			            url: "/templet/planTemplet/file.html",
			            width: 650,
			            height: 400,
			            allowResize: false,
			            onload: function () { 
                    	 	var iframe = this.getIFrameEl();
	                      	var data = {"id":i}
	                        iframe.contentWindow.SetData(data);
	                    },
			            ondestroy: function (action) {
			                if (action == "ok") {
			                    var iframe = this.getIFrameEl();
			                    var data = iframe.contentWindow.GetData();
			                    data = mini.clone(data);
			                    var json = mini.encode(data);
			                    alert("已完成上传数据：\n" + json);
			                }
			            }
			        })
			}
		    
		    function setSuccess(){
		    	   var datagrid = mini.get("datagrid1");
					var dd={"followPlanId":i};
		    		datagrid.reload(dd);
		    }
		    //附件下载
		    function downFile(url,name){
				window.location.href = "/ftp/downFile?path="+url+"&fileName="+name; 
		    }
		    //模板下载
		    function downExcel(){
				window.location.href = "/ftp/downFile?path=/templateFile/工程报建跟进导入模板.xls&fileName=工程报建跟进导入模板.xls"; 
		    }
		    
		</script>
    </body>  
</html>  